import request from "./useRequests";
import { userinfo } from '@/stores/counter'
import { ElMessage } from 'element-plus'

export default function createDiscussion() {
    const user = userinfo()
    async function createDiscussionByCate(content: string, discussionCateId: number) {
        try {
            const res = await request.post('/user/createDiscussion', {
                "content": content,
                "discussionCateId": discussionCateId,
            })
            if (res.data.success) {
                ElMessage({
                    showClose: true,
                    message: '参与成功',
                    type: 'success',
                })
                return res.data.data
            }
            else {
                ElMessage({
                    showClose: true,
                    message: res.data.message,
                    type: 'error',
                })
                return null
            }
        } catch (err: any) {
            //alert(err)
        }
    }

    return {
        createDiscussionByCate
    }
}